interface Teacher {
  teach(): void
}
interface Student {
  study(): void
}
function getPerson(): Teacher | Student {
  return {
    teach() { console.log('teach'); },
    study() { console.log('study'); }
  } as Teacher
}
const person = getPerson()
// ;(<Teacher>person).teach()
// ;(<Student>person).study()

function isTeacher(person: Teacher | Student): person is Teacher {
  return (<Teacher>person).teach !== undefined;
} //  person is Teacher就是类型保护语句，必须是主谓宾结构
if(isTeacher(person)) {
  person.teach()
} else {
  person.study()
}